/*SSVRjXkgvV55TIxKIO0zV6w7SOJByzTfQFu/7tpu3TdrCTYJkSaHXcEmSDpDo9fV*/
import {getBusinessInfo } from 'nc-lightapp-front';
import afterEvent from '../events/afterEvent.js';
function onBatchChange(param){
    let self=this;
    let  {areaCode, column, newValue, changedrows,allData,currentIndex, pasteData}=param;
   // { areaCode, column, newValue, changerows,currentIndex, pasteData}
   //循环判断单元格是否可编辑，并注册过滤条件
   let attrcode=column.attrcode;
   let queryValue =[];
   let newRows = [];
   let queryCondition = {}
   let isManyCondition =true //业务组判断，每行参展过滤条件是否不一样，如果不一样，值为true
   let indexs = [];
    for(let i= 0;i<newValue.length;i++){
        if(allData[i+currentIndex]&&allData[i+currentIndex].values&&allData[i+currentIndex].values[attrcode]){//若该单元可编辑
            newRows[i] = cloneObjectFn(allData[i]);
            newRows[i].values[attrcode] = newValue[i].values[attrcode];
            newRows[i].rowid = newValue[i].rowid;
            newRows[i].status =  newValue[i].status;
            indexs.push(i+currentIndex);
            queryValue[i]=newValue[i]; //则保留
            if(i+currentIndex > allData.length){
                // 因为可以粘贴超过当前页面显示数据的行数，则会增行，如果该行还有其他的数据展示，需要业务组来处理，塞到queryValue中
                // 比如 queryValue[i].values.行号={value：10}
            }
             //若为参照
             if (column.itemtype === 'refer' && isManyCondition) {
                // 每行参照过滤条件是不一样
                setQueryCondition(self, newRows[i], allData[i], self.props, areaCode, attrcode)

            }
        }
    }
    //调用平台方法，更新数据
    self.props.cardTable.updateAfterBatchChange({
        areaCode,
        column,
        queryValue, 
        changedrows,
        pasteData,
        indexs, //过滤后的index的数组例如：[0,1,2,3,5]
        queryCondition, //如果是参照且参照过滤条件唯一就传，不一致就是前面说的，放到queryValue里
        isManyCondition,// true，代表有多个参照过滤条件，false表示只有一个
    }).then((res)=>{

        let { props, changedrows, indexs, key } = res
        //res里的数据，需要什么，我再给你传，暂时有props，changedrows，indexs
        // if(changedrows){//科目由于没有nodedata数据做不了编辑后
        //     changedrows.map((changeValue,index)=>{
        //         afterEvent.call(self,props, areaCode, key,changeValue.newvalue, changedrows, indexs[index], newValue[index]); 
        //     })
        // }
        
    });

}
function onBatchSelected(params){

}
function getAccountQryCondition(page){
	let bizeInfo = getBusinessInfo();
	let {pk_accountingbook} = page.cacheUtil.getListState();
	let dateStr = bizeInfo.businessDate.split(' ')[0];
	let isDataPowerEnable =  'Y';
	let DataPowerOperationCode = 'fi';
	return {pk_accountingbook, dateStr, isDataPowerEnable, DataPowerOperationCode};
}
function cloneObjectFn (obj){ // 对象复制
    return JSON.parse(JSON.stringify(obj))
}
function setQueryCondition(that, newRow, record, props, moduleId, attrcode) {

    switch (attrcode) {
        case 'pk_accasoa'://财务组织
            newRow.isAccountRefer = true;
            newRow.isMultiSelectedEnabled = true;
            newRow.isShowDisabledData = false;
            newRow.queryCondition = () => {
                //查询条件不写成数组，而是取核算账簿数组的第一个
                return getAccountQryCondition(page);
            }
            break;
        default:
            newRow.queryCondition = (p) => {
                return {
                    isDataPowerEnable : 'Y',
                    DataPowerOperationCode :'fi'
                };
            }
        break;
    }
}
export{onBatchChange,onBatchSelected}
/*SSVRjXkgvV55TIxKIO0zV6w7SOJByzTfQFu/7tpu3TdrCTYJkSaHXcEmSDpDo9fV*/